<?php


namespace Bxy\Jwt\middleware;

use Hyperf\HttpMessage\Cookie\Cookie;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Bxy\Jwt\JwtAuth as Auth;


class BaseMiddleware
{
    protected $auth;

    public function __construct(Auth $auth)
    {
        $this->auth = $auth;
    }

    protected function setAuthentication($response, $token = null)
    {
        $token = $token ?: $this->auth->refresh();
        $cookie = new Cookie('token',$token);
        $this->auth->setToken($token);

        return $response->header(['Authorization' => 'Bearer '.$token]);
    }

}
